package com.gg.hj.service.impl;

import com.gg.common.mapper.DFileMapper;
import com.gg.common.mapper.SCellMapper;
import com.gg.common.pojo.DFile;
import com.gg.common.pojo.SCell;
import com.gg.hj.search.S_CellSearch;
import com.gg.hj.service.S_CellService;
import com.gg.hj.util.INumber;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class S_CellServiceImpl implements S_CellService {
    @Resource
    private SCellMapper cellMapper;
    @Resource
    private DFileMapper fileMapper;
    @Resource
    private INumber iNumber;
    @Override
    // TODO 配置安全库存
    public int constituteSCellService(SCell sCell){
        try{
            String number = iNumber.number("400");
            sCell.setStoreId(number);//设置库存流水号
            this.cellMapper.insertSelective(sCell);//配置安全库存
            this.fileMapper.updateDesignStatus(sCell.getProductId());//修改库存标志
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    //TODO 查询安全库存配置单复核
    public S_CellSearch<SCell> queryInventoryReviewAllService(S_CellSearch<SCell> cellSearch) throws Exception {
        PageHelper.startPage(cellSearch.getPageNum(),cellSearch.getPageSize());
        PageInfo<SCell> pageInfo = new PageInfo<SCell>(this.cellMapper.queryInventoryReviewAll());
        cellSearch.setTotal(pageInfo.getTotal());
        cellSearch.setRows(pageInfo.getList());
        return cellSearch;
    }

    @Override
    //TODO 复核 变更 安全库存单
    public int constituteUpdateSCellCheckService(SCell cell) throws Exception {
        return this.cellMapper.updateByPrimaryKeySelective(cell);
    }

    @Override
    //TODO 安全库存配置单查询
    public S_CellSearch<SCell> queryAllService(S_CellSearch<SCell> cellSearch) throws Exception {
        PageHelper.startPage(cellSearch.getPageNum(),cellSearch.getPageSize());
        PageInfo<SCell> pageInfo = new PageInfo<SCell>(this.cellMapper.queryAll());
        cellSearch.setTotal(pageInfo.getTotal());
        cellSearch.setRows(pageInfo.getList());
        return cellSearch;
    }

    @Override
    //TODO 安全库存配置查询变更
    public S_CellSearch<SCell> searchQueryCheckTagService(S_CellSearch<SCell> cellSearch) throws Exception {
        PageHelper.startPage(cellSearch.getPageNum(),cellSearch.getPageSize());
        PageInfo<SCell> pageInfo = new PageInfo<SCell>(this.cellMapper.searchQueryCheckTag());
        cellSearch.setTotal(pageInfo.getTotal());
        cellSearch.setRows(pageInfo.getList());
        return cellSearch;
    }
}
